﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using IronCow.Search;

namespace IronCow.UnitTests
{
    [TestFixture]
    public class TestBooleanNode
    {
        [Test]
        public void TestParentingAndReplacing()
        {
            var node = new BooleanNode(BooleanType.And);

            var child1 = new TermNode("test1");
            var child2 = new TermNode("test2");
            Assert.IsNull(child1.Parent);
            Assert.IsNull(child2.Parent);

            node.LeftChild = child1;
            Assert.AreSame(node.LeftChild, child1);
            Assert.AreSame(node, child1.Parent);

            node.LeftChild = child2;
            Assert.AreSame(node.LeftChild, child2);
            Assert.AreSame(node, child2.Parent);
            Assert.IsNull(child1.Parent);
        }

        [Test]
        public void TestDoubleParenting()
        {
            var node = new BooleanNode(BooleanType.And);

            var child1 = new TermNode("test1");
            var child2 = new TermNode("test2");
            Assert.IsNull(child1.Parent);
            Assert.IsNull(child2.Parent);

            node.LeftChild = child1;
            node.RightChild = child2;
            Assert.AreSame(node.LeftChild, child1);
            Assert.AreSame(node, child1.Parent);
            Assert.AreSame(node.RightChild, child2);
            Assert.AreSame(node, child2.Parent);
        }
    }
}
